package com.moralesce.gt.model;

/**
 * The thirteen different hierarchical values in a deck of cards.
 * 
 * <p>
 * A deck of cards has thirteen ranks: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen,
 * King, Ace.
 * </p>
 * 
 * <p>
 * The ranks have a natural order, with the weakest value (0) assigned to the 2
 * and the strongest value (12) assigned to the ace.
 * </p>
 * 
 * @author Brandon Grenier
 */
public enum Rank {

	TWO(2, "2", 0), THREE(3, "3", 1), FOUR(5, "4", 2), FIVE(7, "5", 3), SIX(11, "6", 4), SEVEN(13, "7", 5), EIGHT(17, "8", 6), NINE(19, "9", 7), TEN(23, "T", 8), JACK(29, "J", 9), QUEEN(31, "Q", 10), KING(37, "K", 11), ACE(41, "A", 12);

	private final Integer id;
	private final String value;
	private final Integer order;

	private Rank(Integer id, String value, Integer order) {
		this.value = value;
		this.order = order;
		this.id = id;
	}

	/**
	 * Returns the rank identifier.
	 * 
	 * @return The unique rank identifier.
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * Returns the rank value.
	 * 
	 * The value will be one of:<br/>
	 * 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A
	 * 
	 * @return The rank value.
	 */
	public String getValue() {
		return value;
	}

	/**
	 * Returns the rank order.
	 * 
	 * @return The rank order.
	 */
	public Integer getOrder() {
		return order;
	}

	/**
	 * Returns the rank for the given value.
	 * 
	 * @param value The value.
	 * 
	 * @return The rank for the given value.
	 * 
	 * @throws IllegalArgumentException if the specified value does not map to a
	 * rank.
	 */
	public static Rank forValue(String value) {
		for (Rank rank : Rank.values()) {
			if (rank.getValue().equalsIgnoreCase(value)) {
				return rank;
			}
		}
		throw new IllegalArgumentException(value + " is not a valid rank");
	}

}
